window.onload = function(){
	var resiter = document.getElementById("resiter");
	var ints = resiter.getElementsByTagName("input");
	var r_btn = resiter.querySelector("button");
	var time_ewm = document.getElementById("timer_ewm");
	var timer = null;
	r_btn.onclick = function(event){
		var user = ints[0].value;
		var password = ints[1].value;
		var password_2 = ints[2].value;
		var phone = ints[3].value;
		var yzm = ints[4].value;
		var phone_yzm = ints[5].value;
		event.preventDefault();
//		判断输入是否为空 start
		for(var i = 0; i < ints.length; i++){
			if(ints[i].value === ""){
				alert("请填写完整信息");
				return;
			}
		}
//		正则 start
		var reg_user = /^[a-zA-Z]\w{7,15}$/;
		var reg_pass = /^\w{7,20}$/;
		var reg_phone = /^1[3-9]\d{9}$/;
		var reg_yzm = /^[a-zA-Z\d]{4}$/;
//		正则 end
		if(user.trim() === "" || !reg_user.test(user)){
			alert("请输入账号\n不能以数字开头，最少8为数");
			return;
		}else if(password.trim() === "" || !reg_pass.test(password)){
			alert("请输入正确的密码");
			return;
		}else if(password_2.trim() === ""){
			alert("密码不可为空");
			return;
		}else if(phone.trim() === "" || !reg_phone.test(phone)){
			alert("请输入正确的手机号码");
			return;
		}else if(phone_yzm.trim() === "" || yzm.trim() === "" || !reg_yzm.test(phone_yzm)){
			alert("请输入正取的验证码");
			return;
		}else if(password !== password_2){
			alert("您输入的密码不一致");
			return;
		}
//		判断输入是否为空 end

		var user_info = {
			"user":user,
			"password":password,
			"password_2":password_2,
			"phone":phone,
		}
		set_localStorage(user_info);
		
		
		if(flag && reg_user.test(user) && reg_pass.test(password) && reg_phone.test(phone)){
			alert("注册成功！");
			location.href = "login.html";
		}
		
		
	}
//	time_ewm
		var count = 60; 
		var ewm_arr = ["1314","3366","9999","4839","0843","2374","2837"];
		time_ewm.onclick = function(){
			clearInterval(timer);
			if(time_ewm.innerHTML === "获取验证码"){
					phone_yzm = ewm_arr[parseInt(Math.random()*6)];
					ints[5].value = phone_yzm;
					console.log(phone_yzm);
			}
			timer = setInterval(function(){
				--count;
				time_ewm.innerHTML = count + "秒";
				if(count < 0){
					time_ewm.innerHTML = "获取验证码";
					count = 60;
					ints[5].value = "";
					clearInterval(timer);
				}
				
			},1000);
		}
}
